<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <TableHeader :buttons="['comSearch']">
            <el-tooltip :content="t('Refresh')" placement="top">
                <el-button v-blur @click="clickRefresh" color="#40485b" class="table-header-operate" type="info">
                    <Icon name="fa fa-refresh" />
                </el-button>
            </el-tooltip>
        </TableHeader>

        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table ref="tableRef" />
    </div>
</template>

<script setup lang="ts">
import { ref, provide, onMounted } from 'vue'
import baTableClass from '/@/utils/baTable'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import { stockInquiry } from '/@/api/backend/xmwms/product'

const { t } = useI18n()
const tableRef = ref()
const baTable = new baTableClass(
    new baTableApi('/admin/xmwms.Product/'),
    {
        pk: 'id',
        column: [
            {
                label: t('xmwms.product.product_no'),
                prop: 'product_no',
                align: 'center',
                width: 150,
                operatorPlaceholder: t('Fuzzy query'),
                operator: 'LIKE',
                sortable: false,
            },
            {
                label: t('xmwms.product.bar_code'),
                prop: 'bar_code',
                align: 'center',
                width: 150,
                operatorPlaceholder: t('Fuzzy query'),
                operator: 'LIKE',
                sortable: false,
            },
            {
                label: t('xmwms.product.name'),
                prop: 'name',
                align: 'center',
                width: 200,
                operatorPlaceholder: t('Fuzzy query'),
                operator: 'LIKE',
                sortable: false,
            },
            {
                label: t('xmwms.product.total_stock_num'),
                prop: 'total_stock_num',
                align: 'center',
                width: 100,
                operator: false,
                sortable: false,
            },
            {
                label: t('xmwms.product.safety_stock_num'),
                prop: 'safety_stock_num',
                align: 'center',
                width: 100,
                operator: false,
                sortable: false,
            },
            {
                label: t('xmwms.product.wms_brand__name'),
                prop: 'wmsBrand.name',
                width: 150,
                align: 'center',
                operatorPlaceholder: t('Fuzzy query'),
                operator: 'LIKE',
            },
            {
                label: t('xmwms.product.warehouse_shelf_id'),
                prop: 'warehouse_shelf_id_text',
                width: 200,
                align: 'center',
                operatorPlaceholder: t('Fuzzy query'),
                render: 'tags',
                operator: false,
                replaceValue: {},
            },
            {
                label: t('xmwms.product.status'),
                prop: 'status',
                align: 'center',
                render: 'tag',
                operator: '=',
                sortable: false,
                replaceValue: { 10: t('xmwms.product.status 10'), 20: t('xmwms.product.status 20') },
            },
            {
                label: t('xmwms.product.createtime'),
                prop: 'create_time',
                align: 'center',
                render: 'datetime',
                operator: 'RANGE',
                sortable: 'custom',
                width: 160,
                timeFormat: 'yyyy-mm-dd hh:MM:ss',
            },
            {
                label: t('xmwms.product.updatetime'),
                prop: 'update_time',
                align: 'center',
                render: 'datetime',
                operator: 'RANGE',
                sortable: 'custom',
                width: 160,
                timeFormat: 'yyyy-mm-dd hh:MM:ss',
            },
        ],
        dblClickNotEditColumn: [undefined],
        defaultOrder: { prop: 'weigh', order: 'desc' },
    },
    {
        defaultItems: {},
    }
)

provide('baTable', baTable)

onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.mount()
    getStockInquiry()
})

const getStockInquiry = () => {
    stockInquiry()
        .then((res) => {
            baTable.table.data = res.data.list
            baTable.table.loading = false
        })
        .catch(() => {
            baTable.form.loading = false
        })
}

const clickRefresh = () => {
    getStockInquiry()
}
</script>

<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
    name: 'xmwms/Product',
})
</script>

<style scoped lang="scss"></style>
